/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mylibrary;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author nafeez
 */
public class Main {

    static void prl(Object o) {
        System.out.println(o);
    }

    public static void main(String[] args) {
        prl("Main Started....");

        Handler handler = new Handler() {

            @Override
            public void handleMessage(Message m) {
                m.printData();
            }
        };
        handler.start();

        int i = 0;
        while (i < 5) {
            AdvancedThread at = new AdvancedThread("Thread - " + i, handler) {

                @Override
                public void threadLoop() {
                    try {
                        sendMessage(new Message(getName()));
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }

                    try {
                        sleep(1000);
                    } catch (InterruptedException ex) {
                        ex.printStackTrace();
                    }
                }
            };
            at.start();
            prl("Thread " + i + " started....");
            i++;

            try {
                Thread.sleep(100);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }

        }

        prl("Main waiting....");
        while (true);


    }
}
